package restaurant;

import restaurant.iterators.Iterator;

/**
 * The Class cmdMenuByRating.
 * 
 * @author Ebonie
 */

public class cmdMenuByRating implements Command
{

	/** The info. */
	private InformationAggregator info;

	/** The rating. */
	private int rating;



	/**
	 * Instantiates a new cmd menu by rating.
	 * 
	 * @param info the info
	 * @param rating the rating
	 */
	public cmdMenuByRating(InformationAggregator info, int rating) {
		this.info = info;
		this.rating = rating;
	}



	/**
	 * Execute.
	 * 
	 * @return the menu by rating.
	 * @see restaurant.Command#execute()
	 */
	@Override
	public Object execute()
	{
		Menu menu = info.getMenu();
		Iterator ratingIterator = menu.getByRatingIterator(rating);
		MenuItem item;
		Menu ratingMenu = new Menu();

		while (ratingIterator.hasNext()) {
			item = (MenuItem) ratingIterator.next();

			if (item.isAvailable())
				ratingMenu.add(item);
		}
		return ratingMenu;
	}

}
